package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.TFileInfoLogModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by lusong on 2017/6/23.
 */
public interface TFileInfoLogRepository extends JpaRepository<TFileInfoLogModel, Integer>, JpaSpecificationExecutor<TFileInfoLogModel> {

    @Query("select a from TFileInfoLogModel a where a.permit = ?1 and a.state = '0' order by a.updateTime")
    List<TFileInfoLogModel> queryUnreadFile(String permit);


    @Query("select a from TFileInfoLogModel a where a.permit = ?1 and a.state = '1' order by a.updateTime desc")
    List<TFileInfoLogModel> queryNewModelByPermit(String permit);

    @Query("select a from TFileInfoLogModel a where a.permit = ?1 order by a.updateTime desc")
    List<TFileInfoLogModel> queryAllModelByPermit(String permit);

    @Modifying
    @Query("delete from TFileInfoLogModel a where a.permit = ?1")
    void deleteModelByPermit(String permit);
}
